package Work323;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Scanner;

public class Studentmanager {
    public static void main(String[] args) {
        Student[] array = new Student[0];
        ArrayList<Student> list = new ArrayList();
        Scanner scanner = new Scanner(System.in);
        int count = 1;
        for (int i = 1;count == 1; i++) {
            int id = i;
            System.out.println("请输入name：");
            String name =scanner.next();
            System.out.println("请输入age：");
            int age =scanner.nextInt();
            System.out.println("请输入geader：");
            String gender =scanner.next();
            System.out.println("继续输入请按1，退出请按其他数字：");
            count = scanner.nextInt();
            if (count != 1){
                System.out.println("退出输入");
                break;
            }
            Student student = new Student(id, name, age, gender);
            list.add(student);
        }
        for (Student student : list) {
            System.out.println(student);
        }

        while (true) {
            System.out.println("按照id搜索输入1：");
            System.out.println("按照name搜索输入2：");
            System.out.println("按照age搜索输入3：");
            System.out.println("按照gender搜索输入4：");
            System.out.println("退出输入0：");
            int type = scanner.nextInt();
            if (type == 0){
                System.out.println("退出搜索");
                break;
            }

            //找到了吗？false 始终没有找到
            boolean isFound = false;
            switch (type){
                case 1:
                    System.out.println("请输入搜索的id：");
                    int id = scanner.nextInt();
                    for (Student student: list){
                        if (student.getId() == id) {
                            System.out.println(student);
                            isFound = true;
                        }
                    }
                    break;
                case 2:
                    System.out.println("请输入搜索的name：");
                    String name = scanner.next();
                    for (Student student: list){
                        if (name.equals(student.getName())) {
                            System.out.println(student);
                            isFound = true;
                        }
                    }
                    break;
            }
            if (! isFound) {
                System.out.println("没有该信息的学生");

            }
        }
        System.out.println("StudentManager.main");
    }

    @Test
    public void test1(){
        String str1 = "zhanggan";
        String str2 = "zhanggan";
        if (str1.equals(str2)){
            System.out.println("==");
        } else {
            System.out.println("!=");
        }
        Person person = new Person();
    }
}
